<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<% String path = request.getContextPath();%>
<jsp:include page="/manage/inc/header"/>
<jsp:include page="/manage/inc/menu"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/static/js/jquery-3.5.1.min.js"></script>

    <!--/sidebar-->
    <div class="main-wrap">

        <div class="crumb-wrap">
            <div class="crumb-list"><i class="icon-font"></i><a href="<%=path%>/manage/index">首页</a><span class="crumb-step">&gt;</span><span class="crumb-name">类型管理</span></div>
        </div>
        <div class="search-wrap">
            <div class="search-content">
                <form action="#" method="post">
                    <table class="search-tab">
                        <tr>

                            <th width="70">菜单名:</th>
    <td><input class="common-text" placeholder="菜单名" name="companyName" value="" id="companyName" type="text"></td>
    <td><input class="btn btn-primary btn2" name="sub" id="search" value="查询" type="button"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">

                <div class="result-title">
                    <div class="result-list">
                        <a href="/manage/menu/insert"><i class="icon-font"></i>新增作品</a>
                        <a id="batchDel" href="javascript:void(0)"><i class="icon-font"></i>批量删除</a>
                        <a id="updateOrd" href="javascript:void(0)"><i class="icon-font"></i>更新排序</a>
                    </div>
                </div>
                <div class="result-content">

                </div>

        </div>
    </div>
    <!--/main-->
</div>
<jsp:include page="/manage/inc/footer"/>
    <script>
    var path="${pageContext.request.contextPath}";
    $(function() {
        var pageNum=1;
        initData(pageNum,null);
    //实现复选框的全选
    $(".result-content").on("click",".allChoose",function () {
    $(":checkbox[id^='choose']").prop("checked",$(this).prop("checked"));


    });
    //批量删除
    $("#batchDel").click(function () {

    var idArr=new Array();
    $(":checked[id^='choose']").each(function () {
    var id = $(this).attr("id").slice(6);
    idArr.push(id);
    });
    if(idArr.length>0)
    {
    $.get(path+"/manage/menu/batchDelete",
    {ids:idArr.toString()},
    function () {
    for(var i=0;i<idArr.length;i++)
    {
    $("#tr"+idArr[i]).remove();
    }
    });
    }

    });
    //点击搜索按钮
    $("#search").click(function () {
    var title=$("#companyName").val();

    initData(pageNum,title);

    });

        //点击页码的时候
    $(".result-content").on("click",".list-page a",function () {
     pageNum=$(this).data("pagenum");
    var title=$("#companyName").val();
    if(title=="") title=null;
    initData(pageNum,title);
    return false;
    });

    //删除
    $(".result-content").on("click",".link-del",function () {
    var id=$(this).data("id");
    var that=this;
    $.get({
    url:path+"/manage/menu/delete",
    data:{id:id},
    success:function () {
    $(this).parent().parent().remove();

    }.bind(this)

    })

    })

    })

    
     function initData(pageNum,title) {
         $.ajax({
        url:path+"/manage/menu/listdata",
         data:{pageNum:pageNum,title:title},
         success:function(result) {
        $(".result-content").html(result);

    }


    });

    }
    </script>
